﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;

public partial class Admin_Locphanconggiaovien : System.Web.UI.Page
{
    BUS_TeacherClass objT = new BUS_TeacherClass();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (Session["AdminLogin"] != null)
        {
            Page.Title = "Lọc Phân Công";
            pnError.Visible = false;
            pnSuccess.Visible = false;
        }
        else Response.Redirect("dangnhap.aspx");
    }
    
    protected void btncapnhatdk_Click(object sender, EventArgs e)
    {
        BUS_TeacherClass objCDL = new BUS_TeacherClass();
        string teacherid = txttimmhs.Text.Trim();
        string classid = txttimml.Text.Trim();
        //string email = txttimemail.Text.Trim();
        //string add = txttimdiachi.Text.Trim();
        //lbthongbao.Text = "SELECT * FROM Customers WHERE Username Like '%"+user+"%' AND Name LIKE '"+name+"' AND Email LIKE '"+email+"' AND Address LIKE '%"+add+"%'";
        var dataCDL = objT.TeacherClass_getSearch(teacherid, classid);
        if (dataCDL.Rows.Count > 0)
        {
            ltrdiv.Text = "<div class='title'>Kết quả tìm kiếm</div>";
            lblSuccess.Text = "Có " + dataCDL.Rows.Count + " kết quả được tìm thấy.";
            pnError.Visible = false;
            pnSuccess.Visible = true;
            //lbthongbao.ForeColor = Color.Blue;
            gvdklop.DataSource = dataCDL;
            gvdklop.DataBind();
        }
        else
        {
            lblError.Text = "Không Tìm thấy Kết quả nào.";
            pnError.Visible = true;
            pnSuccess.Visible = false;
            //lbthongbao.ForeColor = Color.Red;
            gvdklop.DataSource = dataCDL;
            gvdklop.DataBind();
        }

    }
    public void LoadData()
    {
        gvdklop.DataSource = objT.TeacherClass_getAllData();
        gvdklop.DataBind();
    }
    protected void btnxoadk_Click(object sender, EventArgs e)
    {
        try
        {
            int count = 0;
            for (int i = 0; i < gvdklop.Rows.Count; i++)
            {
                CheckBox chk = (CheckBox)gvdklop.Rows[i].Cells[0].FindControl("chkdk");
                if (chk.Checked)
                {
                    count++;
                    int id = int.Parse(gvdklop.Rows[i].Cells[1].Text);
                    //lap danh sach xoa
                    objT.TeacherClass_addtodel(id);
                }
            }
            //tien hanh xoa
            if (count > 0)
            {
                if (objT.TeacherClass_del())
                {
                    LoadData();
                }
                else
                {
                    Response.Write("<script>alert(\"Xóa không thành công\")</script>");
                }
            }
            else Response.Write("<script>alert(\"Bạn chưa chọn mục xóa\")</script>");

        }
        catch (Exception ex)
        {

            throw new Exception(ex.Message);
        }
    }
}